package com.lxs.legou.order.controller;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.lxs.legou.core.controller.BaseController;
import com.lxs.legou.order.config.TokenDecode;
import com.lxs.legou.order.po.Address;
import com.lxs.legou.order.service.AddressService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Auther: Mcb
 * @Date: 2022/1/19 23:51
 * @Description:
 */
@RestController
@RequestMapping("/address")
public class AddressController extends BaseController<AddressService, Address> {

    @Autowired
    private TokenDecode tokenDecode;

    /**
     * 根据实体条件查询
     *
     * @param entity
     * @return
     */
    @ApiOperation(value = "查询",notes = "根据实体条件查询")
    @RequestMapping(value = "/list",method = {RequestMethod.POST,RequestMethod.GET})
    @Override
    public List<Address> list(Address entity) {
        String userName = null;
        try {
            userName = tokenDecode.getUserInfo().get("user_name");
        } catch (JsonProcessingException e) {
            e.printStackTrace();
        }
        entity.setUsername(userName);
        return service.list(entity);
    }
}
